package com.zcoj.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zcoj.mapper.TagMapper;
import com.zcoj.pojo.Dto.Tag;
import com.zcoj.service.TagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * Service实现
 * @author 剩xia的盛夏
 * @date 2023/02/24 16:16
 */
@Service
public class TagServiceImpl implements TagService {

    @Autowired
    private TagMapper tagMapper;

    @Override
    public Integer create(Tag tag) {
        tagMapper.insert(tag);
        return tag.getId();
    }


    @Override
    public Tag findById(Integer id) {
        return tagMapper.selectById(id);
    }

    @Override
    public Tag findOne(Tag tag) {
        Wrapper<Tag> wrapper = new QueryWrapper<>(tag);
        return tagMapper.selectOne(wrapper);
    }
    @Override
    public Integer deleteById(Integer id) {
        return tagMapper.deleteById(id);
    }

    @Override
    public void deleteByIdInBatch(List<Integer> ids) {
        if (CollectionUtils.isEmpty(ids)) return;
        tagMapper.deleteBatchIds(ids);
    }

    @Override
    public Integer updateById(Tag tag) {
       return   tagMapper.updateById(tag);
    }

    @Override
    public void updateByIdInBatch(List<Tag> tags) {
        if (CollectionUtils.isEmpty(tags)) return;
        for (Tag tag: tags) {
            this.updateById(tag);
        }
    }


    @Override
    public List<Tag> findList(Tag tag) {
        Wrapper<Tag> wrapper = new QueryWrapper<>(tag);
        return tagMapper.selectList(wrapper);
    }

    @Override
    public long count(Tag tag) {
        Wrapper<Tag> wrapper = new QueryWrapper<>(tag);
        return tagMapper.selectCount(wrapper);
    }
}
